<template>
  <view class="report-container">
    
    <view class="report-content">
      <view class="report-item">
        <text class="item-label">检测时间</text>
        <text class="item-value">{{ reportData.testTime || '--' }}</text>
      </view>
      
      <view class="report-item">
        <text class="item-label">水质状态</text>
        <text class="item-value" :class="reportData.status === 'good' ? 'status-good' : 'status-bad'">
          {{ reportData.waterQuality || '--' }}
        </text>
      </view>
      
      <view class="report-details">
        <view class="detail-item" v-for="(item, index) in reportData.details" :key="index">
          <text class="detail-label">{{ item.label }}</text>
          <text class="detail-value">{{ item.value }}</text>
          <text class="detail-unit">{{ item.unit }}</text>
        </view>
      </view>
    </view>
    
    <button class="share-btn" @click="handleShare">分享报告</button>
  </view>
</template>

<script>
export default {
  data() {
    return {
      reportData: {
        testTime: '',
        waterQuality: '',
        status: '',
        details: []
      }
    }
  },
  
  onLoad(options) {
    // 获取报告数据
    this.getReportData()
  },
  
  methods: {
    getReportData() {
      // TODO: 从API获取报告数据
      // 示例数据
      this.reportData = {
        testTime: '2025-02-20 22:12',
        waterQuality: '优质',
        status: 'good',
        details: [
          { label: 'TDS值', value: '123', unit: 'mg/L' },
          { label: 'pH值', value: '7.2', unit: '' },
          { label: '浑浊度', value: '0.3', unit: 'NTU' }
        ]
      }
    },
    
    handleShare() {
      uni.share({
        provider: 'weixin',
        scene: 'WXSceneSession',
        type: 0,
        title: '水质检测报告',
        summary: `检测时间：${this.reportData.testTime}，水质状态：${this.reportData.waterQuality}`,
        success: function (res) {
          console.log('success:' + JSON.stringify(res));
        },
        fail: function (err) {
          console.error('fail:' + JSON.stringify(err));
        }
      });
    }
  }
}
</script>

<style lang="scss" scoped>
.report-container {
  padding: 30rpx;
  background-color: #f5f5f5;
  min-height: 100vh;
}

.report-header {
  text-align: center;
  margin-bottom: 40rpx;
  
  .report-title {
    font-size: 36rpx;
    font-weight: bold;
    color: #333;
  }
}

.report-content {
  background-color: #fff;
  border-radius: 16rpx;
  padding: 30rpx;
  margin-bottom: 40rpx;
}

.report-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30rpx;
  
  .item-label {
    color: #666;
    font-size: 28rpx;
  }
  
  .item-value {
    font-size: 28rpx;
    font-weight: 500;
    
    &.status-good {
      color: #07c160;
    }
    
    &.status-bad {
      color: #ff4d4f;
    }
  }
}

.report-details {
  margin-top: 30rpx;
  border-top: 1rpx solid #eee;
  padding-top: 30rpx;
  
  .detail-item {
    display: flex;
    align-items: center;
    margin-bottom: 20rpx;
    
    .detail-label {
      color: #666;
      font-size: 28rpx;
      width: 180rpx;
    }
    
    .detail-value {
      font-size: 28rpx;
      color: #333;
      margin-right: 10rpx;
    }
    
    .detail-unit {
      font-size: 24rpx;
      color: #999;
    }
  }
}

.share-btn {
  width: 90%;
  height: 88rpx;
  line-height: 88rpx;
  text-align: center;
  background-color: #07c160;
  color: #fff;
  border-radius: 44rpx;
  margin: 0 auto;
  font-size: 32rpx;
}
</style>
